package com.droidcar;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;

import act.droidcar.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterSppinerKms extends BaseAdapter {
	/**
	 * Adaptador de listagem das kilometragens armazenados no banco e retornados a partir de um ArrayList de KmlBD
	 */	
	 
    private LayoutInflater mInflater;
    private ArrayList<KmBD> itens;
    private NumberFormat fmt = NumberFormat.getNumberInstance();
 
    public AdapterSppinerKms(Context context, ArrayList<KmBD> itens) {
        this.itens = itens;
        mInflater = LayoutInflater.from(context);
    }
 
    /**
     * Retorna a quantidade de itens
     */
    public int getCount() {
        return itens.size();
    }
 
    /**
     * Retorna o item de acordo com a posicao dele na tela.
     */
    public KmBD getItem(int position) {
        return itens.get(position);
    }
 
    /**
     *
     * @param position
     * @return
     */
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View view, ViewGroup parent) {
    	KmBD item = itens.get(position);
        view = mInflater.inflate(R.layout.item_spinner, null); 
        ((TextView) view.findViewById(R.id.text)).setText( fmt.format(item.getKM_ATE() ) );
        return view;
    }
}

